package com.framework.base.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/05/05 09:48
 */
public class UserServiceProxy implements InvocationHandler {
    private Object object;

    public Object getInstance(Object o) {
        this.object=o;
        return Proxy.newProxyInstance(o.getClass().getClassLoader(),o.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println(Thread.currentThread().getName()+" proxy" +object.getClass());
        Object result = method.invoke(object, args);
        return result;
    }
}
